/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import org.codehaus.groovy.grails.plugins.springsecurity.Secured

/**
 *
 * @author ddevore
 */
abstract class AbstractSecurity {

    def authenticateService

    boolean isLoggedIn() {
        if (!authenticateService) {
            return false
        }
        return authenticateService.isLoggedIn()
    }

    boolean isAdmin() {
        if (!authenticateService) {
            return false
        }
        return authenticateService.ifAnyGranted("ROLE_ADMIN")
    }

    boolean isPowerUser() {
        if (!authenticateService) {
            return false
        }
        return authenticateService.ifAnyGranted("ROLE_POWER_USER") || isAdmin()
    }

    long getUserId() {
        if (!authenticateService) {
            return -1
        }
        return getUser().id
    }

    Object getUser() {
        if (!authenticateService) {
            return null
        }
        return authenticateService.userDomain()
    }
}

